package com.example.text8;

import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import java.io.File;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class VideoFileActivity extends AppCompatActivity {
    @BindView(R.id.btn_open)
    Button btn_open;
    @BindView(R.id.edt_file)
    EditText edt_file;

    private String fileName;
    private Unbinder unbinder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_file);
        unbinder = ButterKnife.bind(this);
    }

    @Override
    protected void onDestroy() {
        if (unbinder != null) {
            unbinder.unbind();
        }

        super.onDestroy();
    }

    @OnClick({R.id.btn_open})
    public void onClick() {
        fileName = edt_file.getText().toString().trim();
        File videoFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + fileName);

        if (videoFile.exists() && videoFile.isFile()) {
            Intent intent = new Intent(VideoFileActivity.this, PlayVideoActivity.class)
                    .putExtra(PlayVideoActivity.VIDEO_PATH, videoFile.getAbsolutePath());
            startActivity(intent);
        } else {
            Toast.makeText(VideoFileActivity.this, "指定播放视频文件不存在", Toast.LENGTH_LONG).show();
        }
    }
}